package Homework;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

/*在你生成的文件中，点名，奇数次点名的名字肯定是
张三-男-23*/
public class work08 {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new FileReader("names.txt"));
        ArrayList<String> list = new ArrayList<>();
        String str = null;
        while ((str = br.readLine()) != null) {
            list.add(str);
        }
        br.close();

        System.out.println("请输入点名同学个数：");
        Scanner sc = new Scanner(System.in);
        Integer strCount = sc.nextInt();
        randomCallName(list,strCount);
    }

    public static void randomCallName(ArrayList<String> list,int count){
        int temp = 0;
        for (int i = 1; i <= count; i++) {
            temp++;
            String calledName = "";

            if (temp % 2 != 0) { // 奇数次点名
                calledName = "张三-男-23";
            } else {
                Collections.shuffle(list);
                calledName = list.get(0);
            }

            System.out.println("第" + i + "次运行程序：随机同学姓名" + i + ": " + calledName);
        }
    }
}
